home *** CD-ROM | disk | FTP | other *** search
- Path: news.netins.net!trg1
- From: hhowe@trgnet.com (Harold Howe)
- Newsgroups: comp.lang.c++
- Subject: Efficiency question: private data
- Date: Wed, 13 Mar 96 21:19:36 GMT
- Organization: Technology Resource Group
- Message-ID: <4i7hfc$8na@insosf1.netins.net>
- NNTP-Posting-Host: desm-21-21.dialup.netins.net
- X-Newsreader: News Xpress Version 1.0 Beta #3
-
- Greetings.
-
- I would like to know what is more efficient: passing data to a member
- function, or storing the data and calling the function with no arguments? For
- example, take the printValue function below.
-
- class SomeClass
- {
- public:
- void printValue(void) { cout << privatevalue;}
- void printValue(int passvalue) { cout << passvalue;}
- private:
- int privatevalue;
- public:
- void setPrivateValue(int value) {privatevalue=value}
- };
-
- int main(void)
- {
- SomeClass A;
- A.setPrivateValue(5);
-
- A.printValue();
- A.printValue(6);
- return 0;
- }
-
- Which is more efficient, and which is better (if their are OO reasons or
- something). I have a more realistic situation in which a class's public
- member function is called with a integer ID argument, then this function
- decides to call a private function which needs to know the integer ID. Should
- I store the ID as a member and call the function with void, or should I call
- the private function with the integer ID as an argument.
-
- All comments are welcome. If you think one method is better for whatever
- reason, please let me know.
-
- Harold Howe
- hhowe@trgnet.com
-
-
-